﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Page.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basePath }style/default.css">
<script>
	var myGrid,treeName,treeId;
	function init() {
		initAuth();
		clickFun();
		addNode();
		initData();
		initEvent();
	}
	function initAuth(){
		if("${CurrentUserBean.authMap.sys_staff_a}"=="1"){
			$("#add").attr("disabled",false);
		}; 
		if("${CurrentUserBean.authMap.sys_staff_u}"=="1"){
			$("#update").attr("disabled",false);
		}; 
		if("${CurrentUserBean.authMap.sys_staff_d}"=="1"){
			$("#delete").attr("disabled",false);
		}; 
		if("${CurrentUserBean.authMap.sys_staff_createUser}"=="1"){
			$("#createAccount").attr("disabled",false);
		}; 
		if("${CurrentUserBean.authMap.sys_staff_dimission}"=="1"){
			$("#leave").attr("disabled",false);
		}; 
	}
	function initData() {
		query();
	}
	function initEvent() {
		
		
		//initHide();
	}
	function addNode() {
		var str = "<div id='example5' class='ezmodal'></div><input type='text' id='sucessUrl' style='display:none'/>";
		$("body").append(str);
	}
	function clickFun() {
		//新增
		$("#add").click(function() {
			SN.getWindowByUrl("新增员工信息", "850", "500", "${basePath}page/system/staff/Staff/toAdd", {});
		});
		//修改
		$("#update").click(function() {
			var v = getGridSelectValues(1);
			if (v.length == 1) {
				SN.getWindowByUrl("修改员工信息", "850", "500", "${basePath}page/system/staff/Staff/toUpd", {
					"map.guid" : v
				});
			} else {
				SN.alert.error("请选择一条记录");
			}
		});
		//创建用户
		$("#createAccount").click(function() {
			var v = getGridSelectValues(1);
			var v1= getGridSelectValues(12);//用户账号
			if (v.length == 1) {
				if(""==v1||"underfine"==v1||v1==null){
					SN.getWindowByUrl("创建账号", "850", "350", "${basePath}page/system/staff/Staff/toCreateAccount", {
						"map.guid" : v
					});
				}else{
					SN.alert.error("该员工已有账号！");
				}
			} else {
				SN.alert.error("请选择一条记录");
			}
			//SN.getWindowByUrl("关联用户组", "800", "400", "${basePath}page/system/user/User/toAddGroup", {});
		});
		//浏览
		$("#view").click(function() {
			var v = getGridSelectValues(1);
			if (v.length == 1) {
				SN.getWindowByUrl("浏览员工信息", "850", "500", "${basePath}page/system/staff/Staff/toView", {
					"map.guid" : v
				});
			} else {
				SN.alert.error("请选择一条记录");
			}
		});
		//高级查询
		$("#query").click(function() {
			SN.getWindowByUrl("高级查询", "800", "400", "${basePath}common/AdvanceQuery.jsp", {});
		});
		//多页添加页面
		// 		$("#addMore").click(function(){
		// 			SN.getWindowByUrl("新增XXX","800","470","${basePath}page1/system/PageMore_Add.jsp",{});
		// 		});
		//上传
		// 		$("#upload").click(function(){
		// 			SN.getWindowByUrl("上传","800","470","${basePath}common/FileUpload.jsp",{});
		// 		});
		//下载
		// 		$("#download").click(function(){
		// 			SN.getWindowByUrl("上传","800","470","${basePath}common/FileDownload.jsp",{});
		// 		});
		//删除
		$("#leave").click(function() {
			var v = getGridSelectValues(1);//guid
			var v1= getGridSelectValues(12);//用户账号
			var v2= getGridSelectValues(11);//离职状态
			
			
			if("离职"==v2){
				SN.alert.error("该员工已离职！");
			}else{
				SN.alert.confirm("是否将在职状态更改为离职状态！", function(obj) {
					if (obj) {
						var v = getGridSelectValues(1);
						$.ajax({
								type : 'POST' ,
								url : '${basePath}page/system/staff/Staff/doLeave' ,
								data : {
									"map.guid" : v ,"map.incumbencyStatus" : "0","map.userAccount" : v1 
								} ,
								dataType : "json" ,
								async : true ,
								cache : false ,
								jsonpCallback : "null" ,
								//beforeSend : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
								//} ,
								//dataFilter : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
								//} ,
								success : function(response, status, statusText) {
									//alert(response + ":" + status + ":" + statusText);
									if (response.status) {
										SN.alert.info(response.content, function() {
											query();
										});
										
										
									} else {
										alert(response.content);
									}
								} ,
								error : function(response, status, statusText) {
									//alert(response + ":" + status + ":" + statusText);
								} ,
								complete : function(response, status, statusText) {
									//alert(response + ":" + status + ":" + statusText);
								}
						});
					}
				});
			}
		});
		//删除
		$("#delete").click(function() {
			var v = getGridSelectValues(1);
			SN.alert.confirm("是否要删除" + v.length + "数据！", function(obj) {
				//SN.alert.confirm("是否更改为离职状态！", function(obj) {
				if (obj) {
					var v = getGridSelectValues(1);
					$.ajax({
							type : 'POST' ,
							url : '${basePath}page/system/staff/Staff/doDel' ,
							data : {
								"map.guid" : v ,
							} ,
							dataType : "json" ,
							async : true ,
							cache : false ,
							jsonpCallback : "null" ,
							//beforeSend : function(response, status, statusText) {
							//alert(response + ":" + status + ":" + statusText);
							//} ,
							//dataFilter : function(response, status, statusText) {
							//alert(response + ":" + status + ":" + statusText);
							//} ,
							success : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
								if (response.status) {
									SN.alert.info(response.content, function() {
										query();
									});
									
									
								} else {
									alert(response.content);
								}
							} ,
							error : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
							} ,
							complete : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
							}
					});
				}
			});
		});
		//重置
		$("#repeat").click(function() {
			window.location.reload();
		});
		//刷新
		$("#refresh").click(function() {
			query();
		});
	}
	//重置查询框
	function clearData() {
		var arr = ['staffName','staffNumCode'];
		for(var key in arr){
			$('#' + arr[key]).val("");
		}
		
	}
	function query(){
		var v = getValue();
		var arr = [
				'staffName' ,
				'staffNumCode'
		];
		$.each(arr, function(key, val) {
			v["map." + val] = $("#" + val).val();
		});
		//v["map.factoryCode"] = $("#factoryCode").val();
		$.ajax({
			type : 'POST' ,
			url : 'page/system/staff/Staff/query' ,
			data : v ,
			dataType : "json" ,
			async : true ,
			cache : false ,
			jsonpCallback : "null" ,
			//beforeSend : function(response, status, statusText) {
			//alert(response + ":" + status + ":" + statusText);
			//} ,
			//dataFilter : function(response, status, statusText) {
			//alert(response + ":" + status + ":" + statusText);
			//} ,
			success : function(response, status, statusText) {
				console.debug(response);
				if (response.status) {
					var a = response.content.currentPageNum;
					var b = response.content.allPageNum;
					var c = response.content.allCount;
					setValue(a, b, c);
				} else {
					alert(response.content);
				}
			} ,
			error : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			} ,
			complete : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			}
		});
	}
</script>

</head>
<style>
.fv-form-bootstrap .help-block {
	width: 0px;
	height: 0px;
}
</style>
<body onload="init()">
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="listTableClass" border="0" cellpadding="0" cellspacing="0">
			<tr class="queryClass">
				<td>
					<table>
						<tr>
							
							<td style="width:20%" class="contClass"><label class="col-xs-3 control-label">员工工号：</label>
								<div class="col-xs-8 ">
									<input class="form-control" type="text" name="map.staffNumCode" id="staffNumCode"  placeholder="" aria-describedby="sizing-addon2" />
								</div></td>
							<td style="width:20%;" class="contClass"><label class="col-xs-3 control-label">员工姓名：</label>
							<div class="col-xs-8 ">
								<input class="form-control" type="text" name="map.staffName" id="staffName"  placeholder="" aria-describedby="sizing-addon2">
							</div></td>
							<td>
								<button onclick="query()" class="btn btn-primary" type="button">
									<span>查询</span>
								</button>
								<button onclick="clearData()" class="btn btn-primary" type="reset">
									<span>清空</span>
								</button>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr class="listTrClass">
				<td>
					<table class="listTableClass">
						<tr class="listContClass">
							<td>
								<div>
									<button class="btn btn-primary" type="button"disabled="disabled"  id="add">
										<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> &nbsp; <span>新增</span>
									</button>
									<button class="btn btn-primary" type="button" disabled="disabled" id="update">
										<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> &nbsp; <span>修改</span>
									</button>
									<button class="btn btn-primary" type="button" disabled="disabled" id="createAccount">
										<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> &nbsp; <span>创建账号</span>
									</button>
									<button class="btn btn-primary" type="button" disabled="disabled" id="leave">
										<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> &nbsp; <span>离职</span>
									</button>
									<button class="btn btn-primary" type="button" id="view">
										<span class="glyphicon glyphicon-file" aria-hidden="true"></span> &nbsp; <span>浏览</span>
									</button>
									<button class="btn btn-primary" type="button" disabled="disabled" id="delete">
										<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> &nbsp; <span>删除</span>
									</button>
									<!-- <button class="btn btn-primary" type="button" id="query">
										<span class="glyphicon glyphicon-search" aria-hidden="true"></span> &nbsp; <span>高级查询</span>
									</button> -->
									<button class="btn btn-primary" type="button" id="refresh">
										<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> &nbsp; <span>刷新</span>
									</button>
									<button class="btn btn-primary" type="button" id="repeat">
										<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span> &nbsp; <span>重置</span>
									</button>
								</div>
							</td>
						</tr>
						<tr class="listTrClass">
							<td><jsp:include page="/common/grid_toolbar.jsp">
									<jsp:param value="query" name="func" />
									<jsp:param value="setValue" name="setValue" />
									<jsp:param value="getValue" name="getValue" />
									<jsp:param value="getGrid" name="getGrid" />
									<jsp:param value="getGridSelectValues" name="getGridSelectValues" />
									<jsp:param value="true" name="isPaging" />
								</jsp:include></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
